// vue中mixins(混入)的使用
// https://blog.csdn.net/weixin_43638968/article/details/108665092?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-1.highlightwordscore&spm=1001.2101.3001.4242.2

export default{
	data(){
		return{
      myInfo:{
        avatar: "http://user.miyun.info/static/images/avatar.png",
        balance: "0.00",
        coin: 0,
        id: 13,
        is_email: 0,
        is_loginEd: true,
        is_mobile: 0,
        is_password: 0,
        level: 0,
        mobile: "",
        nickname: "一顿胖三斤",
        platform: 3,
        score: 0,
        total_amount: "0.00",
        username: "一顿胖三斤",
        is_loginEd:false
      } 
		}
	},
    computed:{
      			tg_Time(){
      				return (d_Time)=>{
      					var date = new Date(d_Time * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
      					var Y = date.getFullYear() + '-';
      					var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1):date.getMonth()+1) + '-';
      					var D = (date.getDate()< 10 ? '0'+date.getDate():date.getDate())+ ' ';
      					var h = (date.getHours() < 10 ? '0'+date.getHours():date.getHours())+ ':';
      					var m = (date.getMinutes() < 10 ? '0'+date.getMinutes():date.getMinutes()) + ':';
      					var s = date.getSeconds() < 10 ? '0'+date.getSeconds():date.getSeconds();
      					return Y+M+D+h+m+s;
      				}
      			}
    },

	mounted() {
		let that=this;
    that.getU_Info(); 
	},
    created() {
      let that=this;
      this.$bus.$on("refreshU_InfoEvent",()=>{
        console.log("refreshU_InfoEvent");
          that.getU_Info();
      });
    },

	methods:{

    getU_Info(){
      let that=this;
      if(window.localStorage.getItem("u_Token")){

        this.$request.get(
          "user/index",
          {

          },
          {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        ).then((res)=>{
         //	console.log("会员信息请求成功：",res);
          that.myInfo=res.data.data.user;
		  that.myInfo.is_loginEd=true;
          this.$store.commit("updateU_Info",that.myInfo);
         })
         .catch((err)=>{
         	console.log("会员信息请求失败：",err);
         });


      }

      // else{
      //   this.$bus.$emit("op_AcpopEvent",true);
      // }
    },
    tz(val){

      if(val!==""){
        if(val=="/write"){
          if(window.localStorage.getItem("u_Token")){
            this.$router.push(val);
          }else{
            this.$bus.$emit("tcAccountPopEvent",true);
          }
        }else{
           this.$router.push(val);
        }

      }

    }
	}
}
